]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
windowManager: Add a generic mechanism for filtering keybindings
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 11 Aug 2012 00:53:38 +0000 (02:53 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Sat, 17 Nov 2012 00:52:51 +0000 (01:52 +0100)
Currently we hardcode the set of keybindings that are available in the
overview; add a generic mechanism to specify in which KeybindingModes
a keybinding should be available.

https://bugzilla.gnome.org/show_bug.cgi?id=688202

js/ui/windowManager.js

index eb7570f480dc7534a094067a3537276ea4d39910..ddebde585801e8e659d494f1156fb39637190e47 100644 (file)
@@ -83,6 +83,8 @@ const WindowManager = new Lang.Class({
 
         this._animationBlockCount = 0;
 
+        this._allowedKeybindings = {};
+
         this._switchData = null;
         this._shellwm.connect('kill-switch-workspace', Lang.bind(this, this._switchWorkspaceDone));
         this._shellwm.connect('kill-window-effects', Lang.bind(this, function (shellwm, actor) {
@@ -143,6 +145,25 @@ const WindowManager = new Lang.Class({
         }));
     },
 
+    setCustomKeybindingHandler: function(name, modes, handler) {
+        if (Meta.keybindings_set_custom_handler(name, handler))
+            this.allowKeybinding(name, modes);
+    },
+
+    addKeybinding: function(name, settings, flags, modes, handler) {
+        if (global.display.add_keybinding(name, settings, flags, handler))
+            this.allowKeybinding(name, modes);
+    },
+
+    removeKeybinding: function(name) {
+        if (global.display.remove_keybinding(name))
+            this.allowKeybinding(name, Main.KeybindingMode.NONE);
+    },
+
+    allowKeybinding: function(name, modes) {
+        this._allowedKeybindings[name] = modes;
+    },
+
     blockAnimations: function() {
         this._animationBlockCount++;
     },
@@ -449,10 +470,15 @@ const WindowManager = new Lang.Class({
                 return false;
         }
 
-        if (Main.modalCount == 0 && binding.is_builtin())
+        // There's little sense in implementing a keybinding in mutter and
+        // not having it work in NORMAL mode; handle this case generically
+        // so we don't have to explicitly allow all builtin keybindings in
+        // NORMAL mode.
+        if (Main.keybindingMode == Main.KeybindingMode.NORMAL &&
+            binding.is_builtin())
             return false;
 
-        return true;
+        return !(this._allowedKeybindings[binding.get_name()] & Main.keybindingMode);
     },
 
     _switchWorkspace : function(shellwm, from, to, direction) {